$(function() {
	var id = "";
	var privilegeApp = new Vue({
		el : '#privilegeApp',
		data : {
			items : [],
			editPrivilege : {}
		},
		methods : {
			// 添加按钮操作
			addBtn : function(event) {
				event.preventDefault();
				$('#addDiv').modal('show');
			},
			// 编辑按钮操作
			editBtn : function(event) {
				var checkBoxArray = $("input:checked");
				id = $("input:checked").val();
				if (checkBoxArray.length > 1) {
					failureTip("只能选择一条记录");
					return;
				}
				if (checkBoxArray.length < 1) {
					failureTip("请选择一条记录操作");
					return;
				}
				$.post(Globals.ctx + "privilege/selectPrivilegeById", {
					id : id
				}, function(data, textStatus, req) {
					privilegeApp.$data.editPrivilege = data.retdata;
				}, 'json');
				event.preventDefault();
				$('#editDiv').modal('show');
			},
			deleteBtn : function(event) {
				var checkBoxArray = $("input:checked");
				id = $("input:checked").val();
				if (checkBoxArray.length > 1) {
					failureTip("只能选择一条记录");
					return;
				}
				if (checkBoxArray.length < 1) {
					failureTip("请选择一条记录操作");
					return;
				}
				event.preventDefault();
				$('#delDiv').modal('show');
			},
			delRecord : function() {
				$.post(Globals.ctx + "privilege/delete", {
					id : id
				}, function(data, textStatus, req) {
					if (data.retcode == 200) {
						successTip(data.retmsg);
					} else {
						failureTip(data.retmsg);
					}
					location.href = Globals.ctx + "privilege/privilegeInfo";
				}, 'json')
			}
		}
	});
	$.post(Globals.ctx + "privilege/privilegeList", {}, function(data,
			textStatus, req) {
		privilegeApp.$data.items = data.retdata.content;
	}, 'json')
});